﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using mitasoft.Web.DAL.Model;

namespace MySite2.Areas.RedZone.Helpers
{
    public class PaginatedListBook : PaginatedList<Book>
    {
        public PaginatedListBook(IQueryable<Book> source, int pageIndex, int pageSize)
            : base(source, pageIndex, pageSize)
        {

        }
    }

    public class PaginatedList<T> : List<T>
    {
        public int PageIndex { get; private set; }
        public int PageSize { get; private set; }
        public int TotalCount { get; private set; }
        public int TotalPages { get; private set; }

        public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
        {
            this.PageSize = pageSize;
            this.PageIndex = pageIndex;
            this.TotalCount = source.Count();
            this.TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);

            this.AddRange(source.Skip((PageIndex - 1) * PageSize).Take(PageSize));
        }
    }
}